package cn.appsys.service.developer;

import cn.appsys.dao.devuser.DevUserMapper;
import cn.appsys.pojo.BackendUser;
import cn.appsys.pojo.DevUser;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class DevUserServiceImpl implements DevUserService {
	@Resource
	private DevUserMapper mapper;
	@Override
	public DevUser login(String devCode, String devPassword) throws Exception {
		DevUser user = null;
		user = mapper.getLoginUser(devCode);
		//匹配密码
		if(null != user){
			if(!user.getDevPassword().equals(devPassword))
				user = null;
		}
		return user;
	}

	@Override
	public BackendUser backLogin(String userCode, String userPassword) throws Exception {
		BackendUser user = null;
		user = mapper.backgetLoginUser(userCode);
		//匹配密码
		if(null != user){
			if(!user.getUserPassword().equals(userPassword))
				user = null;
		}
		return user;
	}

    @Override
    public void checkUser(int backId,String devCode) {
        mapper.checkUser(backId,devCode);
    }

    @Override
    public int getUserCount(String queryUserName) {

		return mapper.getUserCount(queryUserName);
    }

	@Override
	public List<DevUser> getUserList(String queryUserName, Integer currentPageNo, int pageSize) {
		return mapper.getUserList(queryUserName,(currentPageNo-1)*pageSize,pageSize);
	}

    @Override
    public void reCheckUser(int userId) {
        mapper.updateCreateBy(userId);
    }

	@Override
	public void deleteUser(int userId) {
		mapper.deleteUser(userId);
	}

    @Override
    public boolean addUser(DevUser devUser) {
        boolean flag = false;
        if (mapper.addUser(devUser) > 0){
        	flag = true;
		}
        return false;

    }

    @Override
    public DevUser getUserByDDevCode(String devCode) {

		return  mapper.getUser(devCode);
    }

    @Override
    public void update(DevUser devUser) {
        mapper.update(devUser);
    }

}
